﻿Imports System.Net.Mail


Partial Class Contact
    Inherits System.Web.UI.Page
    Private ReadOnly _el As New errorLog

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
    Protected Sub BtnSendEmailClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnSendEmail.Click
        Dim mail As MailMessage = New MailMessage()
        Dim sd As System_Defaults = New System_Defaults
        sd.GetSystemDefault("AdminEmail")
        Dim strFrom As String = sd.FieldValue
        sd.GetSystemDefault("EmailPassword")
        Dim strPassword As String = sd.FieldValue
        sd.GetSystemDefault("EmailHost")
        Dim strEmailHost As String = sd.FieldValue
        mail.To.Add("toaddress@domain.com")
        mail.From = New MailAddress(Me.txtFrom.Text)
        mail.Subject = Me.txtSubject.Text
        mail.Body = Me.txtMessage.Text

        Try
            mail.IsBodyHtml = True
            Dim smtp As SmtpClient = New SmtpClient()
            smtp.Host = strEmailHost
            smtp.Credentials = New System.Net.NetworkCredential(strFrom, strPassword)
            smtp.EnableSsl = True
            smtp.Port = 587
            smtp.EnableSsl = True
            smtp.Send(mail)

            Me.lblOutputMessage.Text = "Email was sent"
        Catch ex As Exception
            _el.CatchError(ex)
        End Try

    End Sub
End Class
